package io.renren.modules.business.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.business.entity.BusProjectDeveloperEntity;
import io.renren.modules.business.service.BusProjectDeveloperService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 开发者管理
 *
 * @author liao mengqing
 */
@RestController
@RequestMapping("business/developer")
public class BusProjectDeveloperController {
    @Autowired
    private BusProjectDeveloperService busProjectDeveloperService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:developer:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = busProjectDeveloperService.queryPage(params);
        return R.ok().put("page", page);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:developer:save")
    public R save(@RequestBody BusProjectDeveloperEntity busProjectDeveloper){
        boolean result = busProjectDeveloperService.isLeader(busProjectDeveloper.getTeamId());
        if (result && busProjectDeveloper.getTeamLeader() == 1) {
            return R.error("抱歉，该团队已有队长！");
        }else {
            busProjectDeveloperService.save(busProjectDeveloper);
            return R.ok();
        }
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:developer:update")
    public R update(@RequestBody BusProjectDeveloperEntity busProjectDeveloper){
		busProjectDeveloperService.updateById(busProjectDeveloper);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:developer:delete")
    public R delete(@RequestBody Long[] developerIds){
		busProjectDeveloperService.removeByIds(Arrays.asList(developerIds));
        return R.ok();
    }
}
